﻿Chenxin.UI.HouseArchivementPage = Chenxin.extend(Chenxin.UI.PageCommon,{
    autoInitForm:false,
    actionUrl:'service/houseArchivement.ashx',
    createGrid:function(){
        var objPg = this;
        return new Chenxin.UI.Pagination({
            actionUrl:this.actionUrl + "?op=Search",
			renderTo:'house_table',
			afterRender:function(data,msg){
			    if(objPg.Parent != undefined){
			        var lsParent = objPg.Parent;
			        $("#report").children("tbody").prepend( lsParent[lsParent.length-1] );
			    }
			}
        })
    },
    initEvent:function(){
        var objPg = this;
        /************事件：向上按钮事件***********/
        $(".clsUp").live("click",function(){
            var params = {};
            var Parent = objPg.Parent;
            var ParentType = $(this).parent("tr").children("td:eq(1)").text();
            var ParentId = $(this).parent("tr").children("td:eq(0)").text();
            var idxOfParent;
            
            //delete Parent[Parent.length-1];
            Parent.splice(Parent.length-1,1);
            if( Parent.length==0 ){
                delete objPg.Parent;
            }else{
                objPg.Parent = Parent;
            }
            
            idxOfParent = ParentType.lastIndexOf("\\");
            if(idxOfParent==-1){
                idxOfParent = 0;
            }
            ParentType = ParentType.substring(0,idxOfParent);
            
            idxOfParent = ParentId.lastIndexOf("\\");
            if(idxOfParent==-1){
                idxOfParent = 0;
            }
            ParentId = ParentId.substring(0,idxOfParent);
            
            params.ParentId = ParentId;
            params.ParentType = ParentType;
           
            Chenxin.apply(params,objPg.search.getParamJson());
            objPg.grid.reload(params);
        });
        /************事件：向下按钮事件***********/
        $(".clsDown").live("click",function(){
            var params = {};
            var parentHtml;
            
            //$(this).parent("tr").children("td:eq(2)").text("向上");
            $(this).parent("tr").children("td:eq(2)").removeClass("clsDown");
            $(this).parent("tr").children("td:eq(2)").addClass("clsUp");
            $(this).parent("tr").children("td:eq(2)").children("div").removeClass("doimg");
            $(this).parent("tr").children("td:eq(2)").children("div").addClass("upimg");
            $(this).parent("tr").children("td:eq(2)").children("div").attr("title","返回上层");
            parentHtml = "<tr>" +  $(this).parent("tr").html() + "</tr>";
            parentHtml = parentHtml + "<tr><td colspan=23></td></tr>";
            
            if(objPg.Parent != undefined){
                var lsParent = objPg.Parent;
                lsParent[lsParent.length] = parentHtml;
                objPg.Parent = lsParent;
            }else{
                var lsParent=new Array();
                lsParent[0] = parentHtml;
                objPg.Parent = lsParent;
            }
            
            params.ParentId = $(this).parent("tr").children("td:eq(0)").text();
            params.ParentType = $(this).parent("tr").children("td:eq(1)").text();
           
            Chenxin.apply(params,objPg.search.getParamJson());
            objPg.grid.reload(params);
        });
    },
    createSearch:function(){
        return new Chenxin.UI.HouseArchivementSearch({
            scope:this
        });
    },
    initComponent:function(){
        this.superclass.initComponent.call(this);
    }
});

/*
**查询面板
*/
Chenxin.UI.HouseArchivementSearch = Chenxin.extend(Chenxin.UI.SearchCommon,{
    actionUrl:'service/houseArchivement.ashx',
    initEvent:function(){
        var objSearch = this;
        /*************事件：查询事件*************/
        $("#btSearch").click(function(){
            if($("#txtStartDate").val() == "" && $("#txtEndDate").val() == ""){
                alert("请输入日期进行检索");
                $("#txtStartDate").focus();
                return;
            }
            delete objSearch.scope.Parent;
            objSearch.scope.reloadGrid();
        });
        /*************事件：昨日营业动态*************/
        $("#aSearchYesterday").click(function(){
            $("#txtStartDate").val(objSearch.lsDate.Yesterday);
            $("#txtEndDate").val(objSearch.lsDate.Yesterday);
            delete objSearch.scope.Parent;
            objSearch.scope.reloadGrid();
        });
        /*************事件：本周营业动态*************/
        $("#aSearchCurWeek").click(function(){
            $("#txtStartDate").val(objSearch.lsDate.CurStartWeekDay);
            $("#txtEndDate").val(objSearch.lsDate.CurEndWeekDay);
            delete objSearch.scope.Parent;
            objSearch.scope.reloadGrid();
        });
        /*************事件：当月营业动态*************/
        $("#aSearchCurMon").click(function(){
            $("#txtStartDate").val(objSearch.lsDate.CurStartMonth);
            $("#txtEndDate").val(objSearch.lsDate.CurEndMonth);
            delete objSearch.scope.Parent;
            objSearch.scope.reloadGrid();
        });
    },
    initComponent:function(){
        this.superclass.initComponent.call(this);
        var lsDate = eval("(" + $("#ctl00_main_lsDate").val() + ")");
        this.lsDate = lsDate;
    }
});

$(document).ready(function(){
    var houseArchivement = new Chenxin.UI.HouseArchivementPage();
});